Coin Problem:

"You place 100 coins heads up in a row and number them by position, with the coin all the way on the left No. 1 and the one on the rightmost edge No. 100. Next, for every number N, from 1 to 100, you flip over every coin whose position is a multiple of N. For example, first you'll flip over every coin whose position is a multiple of N. For example. First you'll flip over all the coins, because every number is a multiple of 1. Then you'll flip over all the even-numbered coins, because theyre multiples of 2. Then you'll flip coins No. 3, 6, 9, 12 and so on."

To solve this puzzle I chose to write some code in Python because I knew it would be relatively trivial to do using a few lines of code. Immediately the problem seemed to be a function using a mathematical expression or concept I'm not yet familiar with. However, I knew that I would always have 100 coins. For each 100 coins I would need to find if n (the "coin") is divisable by the value of the current iteration such that the result will be zero. In other words, if something is a multiple of three for example then it could also be divided by three and the result of that division would be zero. If we were to continue where the word problem left off at iteration 13, we would divide the first coin which is one by 13 and the answer would be 0.076923077, next we would try to divide 2 by 13 and get 0.153846154. Still we would not have zero so we wouldn't flip the first or second coin. All the way until we reach the 13th coin, in which case 13 is divisible by 13 and it's also a multiple of 13 because 1 * 13 = 13. My algorithm simply accounts for the iteration or N in our word problem using one loop, then within that loop there's another loop that prints 100 "coins"... If the result of division by N is equal to zero the coin is "flipped" and is printed, otherwise it is simply printed as unchanged. The ouput of my program shows a nice visual for the result of the puzzle. I would be interested in knowing the mathematical vocabulary to this puzzle.


In [5]:
from coins import *

In [6]:
token = '·'; fill = ' '

coin_flip(token, fill)


                                                                                                    
····································································································
 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  · 
   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·   ·
    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·    ·
     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·     ·    
      ·      ·      ·      ·      ·      ·      ·      ·      ·      ·      ·      ·      ·      ·  
       ·       ·       ·       ·       ·       ·       ·       ·       ·       ·       ·       ·    
        ·        ·        ·        ·        ·        ·        ·        ·        ·        ·        · 
         ·         ·         ·         ·         ·         ·         ·         ·         ·         ·
          ·          ·          ·          ·          ·          ·          ·          ·          · 
           ·           ·           ·           ·           ·           ·           ·           ·    
            ·            ·            ·            ·            ·            ·            ·         
             ·             ·             ·             ·             ·             ·             ·  
              ·              ·              ·              ·              ·              ·          
               ·               ·               ·               ·               ·               ·    
                ·                ·                ·                ·                ·               
                 ·                 ·                 ·                 ·                 ·          
                  ·                  ·                  ·                  ·                  ·     
                   ·                   ·                   ·                   ·                   ·
                    ·                    ·                    ·                    ·                
                     ·                     ·                     ·                     ·            
                      ·                      ·                      ·                      ·        
                       ·                       ·                       ·                       ·    
                        ·                        ·                        ·                        ·
                         ·                         ·                         ·                      
                          ·                          ·                          ·                   
                           ·                           ·                           ·                
                            ·                            ·                            ·             
                             ·                             ·                             ·          
                              ·                              ·                              ·       
                               ·                               ·                               ·    
                                ·                                ·                                · 
                                 ·                                 ·                                
                                  ·                                  ·                              
                                   ·                                   ·                            
                                    ·                                    ·                          
                                     ·                                     ·                        
                                      ·                                      ·                      
                                       ·                                       ·                    
                                        ·                                        ·                  
                                         ·                                         ·                
                                          ·                                          ·              
                                           ·                                           ·            
                                            ·                                            ·          
                                             ·                                             ·        
                                              ·                                              ·      
                                               ·                                               ·    
                                                ·                                                ·  
                                                 ·                                                 ·
                                                  ·                                                 
                                                   ·                                                
                                                    ·                                               
                                                     ·                                              
                                                      ·                                             
                                                       ·                                            
                                                        ·                                           
                                                         ·                                          
                                                          ·                                         
                                                           ·                                        
                                                            ·                                       
                                                             ·                                      
                                                              ·                                     
                                                               ·                                    
                                                                ·                                   
                                                                 ·                                  
                                                                  ·                                 
                                                                   ·                                
                                                                    ·                               
                                                                     ·                              
                                                                      ·                             
                                                                       ·                            
                                                                        ·                           
                                                                         ·                          
                                                                          ·                         
                                                                           ·                        
                                                                            ·                       
                                                                             ·                      
                                                                              ·                     
                                                                               ·                    
                                                                                ·                   
                                                                                 ·                  
                                                                                  ·                 
                                                                                   ·                
                                                                                    ·               
                                                                                     ·              
                                                                                      ·             
                                                                                       ·            
                                                                                        ·           
                                                                                         ·          
                                                                                          ·         
                                                                                           ·        
                                                                                            ·       
                                                                                             ·      
                                                                                              ·     
                                                                                               ·    
                                                                                                ·   
                                                                                                 ·  
                                                                                                  · 
                                                                                                   ·
""" coins.py | Tue, Feb 07, 2017 | Roman S. Collins

The problem:

You place 100 coins heads up in a row and number them by position, with the coin all the way on the left No. 1 and the one on the rightmost edge No. 100. Next, for every number N, from 1 to 100, you flip over every coin whose position is a multiple of N. For example, first you'll flip over every coin whose position is a multiple of N. For example. First you'll flip over all the coins, because every number is a multiple of 1. Then you'll flip over all the even-numbered coins, because theyre multiples of 2. Then you'll flip coins No. 3, 6, 9, 12 and so on.

"""
import time

def coin_flip(token, fill):
    # print 100 "coins"
    for i in range(1, 100 + 1):
        print(fill, end='')
    print('')
    # i becomes the function
    # in this unkown mathematical
    # expression
    for i in range(1, 100 + 1):
        # start flipping to heads
        for n in range(1, 100 + 1):
            if n % i == 0:
                print(token, end='')
            else:
                print(fill, end='')
        print('')
        time.sleep(0.005)

def main():
    token = '·'; fill = ' '

    coin_flip(token, fill)

if __name__ == '__main__':
    main()

In [ ]: